package diva.pap.merchant;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import diva.android_library.ActivityPresenter;
import diva.android_library.rpc.Response;
import diva.lib.event.Event;
import diva.lib.event.Listener;
import diva.pap.R;
import diva.pap.model.Application;

public class WaitingTasksPresenter extends ActivityPresenter {

  public WaitingTasksPresenter(Activity activity) {
    super(activity);
  }

  public void onCreate(Bundle state) {
    setContentView(R.layout.waiting_tasks);
    load();
    getButton(R.id.button_reload).setOnClickListener(new OnClickListener() {
      public void onClick(View v) {
        Application.getInstance().reload();
      }
    });
    attach(Application.getInstance().getEventReload(), new Listener<Void>() {
      public void onEvent(Event<Void> event, Void arg) {
        load();
      }
    });
  }

  protected void load() {
    new WaitingTasksRequest(activity, new Response<WaitingTasksRequest>() {
      public void onReuestDone(WaitingTasksRequest data) {
        getTextView(R.id.waitingtasks_pendingaffiliates_value).setText(data.getPendingAffiliates());
        getTextView(R.id.waitingtasks_pendingcommisions_value).setText(data.getPendingCommisions());
        getTextView(R.id.waitingtasks_pendinglinks_value).setText(data.getPendingLinks());
      };

      public void onReuestFailed() {}
    }).send();
  }

}
